import 'package:banyou_app/app/config/colors.dart';
import 'package:banyou_app/app/util/common_utils.dart';
import 'package:banyou_app/app/widget/app_bar_widget.dart';
import 'package:banyou_app/app/widget/load_network_image_widget.dart';
import 'package:banyou_app/app/widget/login_button.dart';
import 'package:banyou_app/app/widget/login_input.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';

import '../controllers/liuyan_controller.dart';

class LiuyanView extends GetView<LiuyanController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBarWidget(),
      body: Column(
        children: [
          Expanded(
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 12, vertical: 5),
              child: SingleChildScrollView(
                child: Column(
                  children: [
                    itemWidget(),
                    Container(width: 1.sw, height: 3, color: Color(0xFFF5F7F9)),
                    Obx(() => ListView.separated(
                        padding: EdgeInsets.zero,
                        shrinkWrap: true,
                        physics: NeverScrollableScrollPhysics(),
                        itemBuilder: (c, i) {
                          return itemWidget1(controller.comments[i]);
                        },
                        separatorBuilder: (c, i) {
                          return Container();
                        },
                        itemCount: controller.comments.length))
                  ],
                ),
              ),
            ),
          ),
          SafeArea(
            child: Container(
              decoration: BoxDecoration(color: Theme.of(context).cardColor),
              child: _buildTextComposer(),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildTextComposer() {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
      color: Colors.white,
      child: Row(
        children: [
          Flexible(
            child: Container(
              decoration: BoxDecoration(
                color: Colors.grey[100],
                // border: Border.all(color: ColorConfig.app_main, width: .5),
                borderRadius: BorderRadius.all(Radius.circular(10.r)),
              ),
              child: LoginInput(
                title: "",
                hint: "请输入评论",
                controller: controller.textController,
                autofocus: true,
                keyBoardType: TextInputType.text,
                onChanged: (text) {
                  controller.text.value = text;
                  controller.checkInput();
                },
              ),
            ),
          ),
          SizedBox(width: 12),
          Container(
            width: 80,
            child: Obx(() => LoginButton(
                  "发表",
                  enable: controller.sendEnable.value,
                  onPressed: controller.send,
                )),
          )
        ],
      ),
    );
  }

  itemWidget1(item) {
    return Container(
      padding: EdgeInsets.symmetric(vertical: 5),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          ClipOval(
            child: LoadNetworkImageWidget(
                fit: BoxFit.cover,
                height: 40,
                width: 40,
                imageUrl: item['UserAvatar'] ?? ""),
          ),
          SizedBox(width: 20),
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  child: Row(
                    children: [
                      Text(
                        item['UserName'] ?? "",
                        style: TextStyle(
                            fontSize: 18.sp,
                            fontWeight: FontWeight.bold,
                            color: ColorConfig.text_label),
                      ),
                      SizedBox(width: 3),
                      Spacer(),
                      Text(
                        item['Distance'] ?? "",
                        style: TextStyle(
                            fontSize: 12.sp, color: Color(0xFF959595)),
                      ),
                    ],
                  ),
                ),
                SizedBox(height: 5),
                Text(
                  item['Content'] ?? "",
                  style:
                      TextStyle(fontSize: 12.sp, color: ColorConfig.text_label),
                ),
                SizedBox(height: 5),
              ],
            ),
          ),
        ],
      ),
    );
  }

  itemWidget() {
    return Obx(() => controller.userMap.isEmpty
        ? Container()
        : Container(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    ClipOval(
                      child: Container(
                        decoration: const BoxDecoration(
                          color: ColorConfig.white,
                          shape: BoxShape.circle,
                          boxShadow: [
                            BoxShadow(
                              color: Color(0xFFE8E8E8),
                              offset: Offset(8, 8),
                              blurRadius: 10,
                              spreadRadius: 1,
                            ),
                          ],
                        ),
                        padding: EdgeInsets.all(10),
                        child: ClipOval(
                          child: LoadNetworkImageWidget(
                              width: 50.w,
                              height: 50.w,
                              fit: BoxFit.cover,
                              imageUrl: controller.userMap['UserAvatar'] ?? ""),
                        ),
                      ),
                    ),
                    Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          children: [
                            Text(
                              controller.userMap['UserName'] ?? "",
                              style: TextStyle(
                                  fontSize: 18.sp,
                                  fontWeight: FontWeight.bold,
                                  color: ColorConfig.text_label),
                            ),
                            SizedBox(width: 3),
                            Row(
                              children: [
                                controller.userMap['UserGender'] == '女'
                                    ? Container(
                                        padding:
                                            EdgeInsets.symmetric(horizontal: 3),
                                        decoration: BoxDecoration(
                                          color: Color(0xFFF8DCEC),
                                          borderRadius: BorderRadius.all(
                                              Radius.circular(8)),
                                        ),
                                        child: Row(
                                          children: [
                                            Image.asset(
                                              'assets/images/女@2x.png',
                                              width: 18,
                                            ),
                                            SizedBox(width: 2),
                                            Text(
                                                '${controller.userMap['UserGender'] ?? ""}',
                                                style: TextStyle(
                                                    fontSize: 10.sp,
                                                    color: Color(0xFFEB6DAF))),
                                            SizedBox(width: 3),
                                          ],
                                        ),
                                      )
                                    : Container(
                                        padding:
                                            EdgeInsets.symmetric(horizontal: 3),
                                        decoration: BoxDecoration(
                                          color: Color.fromARGB(
                                              255, 198, 211, 240),
                                          borderRadius: BorderRadius.all(
                                              Radius.circular(8)),
                                        ),
                                        child: Row(
                                          children: [
                                            Image.asset(
                                              'assets/images/nan.png',
                                              width: 20,
                                            ),
                                            SizedBox(width: 2),
                                            Text(
                                                '${controller.userMap['UserGender'] ?? ""}',
                                                style: TextStyle(
                                                    fontSize: 10.sp,
                                                    color: Color.fromARGB(
                                                        255, 88, 97, 237))),
                                            SizedBox(width: 3),
                                          ],
                                        ),
                                      ),
                                // controller.userMap['UserGender'] == '女'
                                //     ? Image.asset(
                                //         'assets/images/女@2x.png',
                                //         width: 18,
                                //       )
                                //     : Image.asset(
                                //         'assets/images/nan.png',
                                //         width: 20,
                                //       ),
                                // Text((controller.userMap['UserAge'] ?? ""),
                                //     style: TextStyle(
                                //         fontSize: 10.sp,
                                //         color: Color(0xFFEB6DAF))),
                              ],
                            )
                          ],
                        ),
                        SizedBox(height: 5),
                        Row(
                          children: [
                            Text(
                              controller.userMap['AddTime'] ?? "",
                              style: TextStyle(
                                  fontSize: 12.sp, color: Color(0xFF959595)),
                            ),
                            Container(
                                width: 1,
                                height: 7,
                                color: Color(0xFF959595),
                                padding: EdgeInsets.symmetric(horizontal: 10)),
                            Text(
                              controller.userMap['Distance'] ?? "",
                              style: TextStyle(
                                  fontSize: 12.sp, color: Color(0xFF959595)),
                            ),
                          ],
                        ),
                      ],
                    )
                  ],
                ),

                // Container(
                //   width: 1.sw,
                //   child: Text(
                //      '${item['ViewNum'] ?? ""}人在看',
                //     style: TextStyle(fontSize: 14.sp, color: ColorConfig.text_label),
                //   ),
                // ),
                Text(
                  controller.userMap['Content'] ?? "",
                  style:
                      TextStyle(fontSize: 14.sp, color: ColorConfig.text_label),
                ),
                // 图片
                if (controller.userMap['PictureUrl'] != null)
                  InkWell(
                    onTap: () {
                      showImgs([controller.userMap['PictureUrl']], 0);
                    },
                    child: Container(
                      padding: EdgeInsets.symmetric(vertical: 5),
                      clipBehavior: Clip.hardEdge,
                      decoration: BoxDecoration(
                        color: ColorConfig.white,
                        borderRadius: BorderRadius.all(Radius.circular(10)),
                      ),
                      child: LoadNetworkImageWidget(
                          fit: BoxFit.fill,
                          width: 1.sw,
                          imageUrl: controller.userMap['PictureUrl']),
                    ),
                  ),
                // 在看
              ],
            ),
          ));
  }
}
